#include <iostream>
#include <memory>
#include "MysqlConn.hpp"
#include "ConnectionPool.hpp"
using namespace std;

int main(int argc, char const *argv[])
{
    // 测试数据库连接
    MysqlConn conn;
    if (conn.connect("username", "password", "database", "127.0.0.1", 3306)) {
        cout << "数据库连接成功!" << endl;
    } else {
        cout << "数据库连接失败!" << endl;
        return -1;
    }

    // 测试连接池
    ConnectionPool* pool = ConnectionPool::getConnectionPool();
    shared_ptr<MysqlConn> connPool = pool->getConnection();
    if (connPool) {
        cout << "从连接池获取连接成功!" << endl;
    } else {
        cout << "从连接池获取连接失败!" << endl;
        return -1;
    }

    // 进行一些数据库操作
    string sql = "SELECT * FROM person";
    if (connPool->query(sql)) {
        while (connPool->next()) {
            cout << connPool->value(0) << ", " << connPool->value(1) << ", " << connPool->value(2) << endl;
        }
    } else {
        cout << "查询失败!" << endl;
    }

    return 0;
}